package com.example.lianjuan.ui.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.adapter.FragmentViewHolder;

import com.example.lianjuan.Model.domain.Categories;
import com.example.lianjuan.ui.frament.HomePagerFrament;

import java.util.ArrayList;
import java.util.List;

public class HomePager2Adapter extends FragmentStateAdapter {
    private List<Categories.DataDTO> mData = new ArrayList<>();

    public HomePager2Adapter(@NonNull FragmentManager fragmentManager, @NonNull Lifecycle lifecycle) {
        super(fragmentManager, lifecycle);
    }


    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return HomePagerFrament.newInstance(mData.get(position));
    }


    @Override
    public int getItemCount() {
        return mData.size();
    }

    public void setCategory(Categories categories) {
        mData.clear();
        List<Categories.DataDTO> data = categories.getData();
        mData.addAll(data);
        notifyDataSetChanged();
    }
}
